package com.tianyang.yukuaifuzs.business.trade.view;

import android.annotation.SuppressLint;
import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.tianyang.yukuaifuzs.R;
import com.tianyang.yukuaifuzs.business.trade.bean.TradeTotalOutput;
import com.tianyang.yukuaifuzs.utils.VerifyUtil;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Description：交易记录顶部view
 * Created by xyj on 2024/3/11
 */
public class TradeRecordHeaderView extends LinearLayout {

    @BindView(R.id.amountTv)
    TextView amountTv;
    @BindView(R.id.countTv)
    TextView countTv;
    @BindView(R.id.totalTv)
    TextView totalTv;

    public TradeRecordHeaderView(Context context, AttributeSet attrs) {
        super(context, attrs);
        View.inflate(getContext(), R.layout.layout_trade_record_header, this);
        ButterKnife.bind(this);
    }

    @SuppressLint("SetTextI18n")
    public void showTradeTotalView(JSONObject jsonObject) {
        if (jsonObject != null) {
            TradeTotalOutput output = JSON.parseObject(jsonObject.toJSONString(), TradeTotalOutput.class);
            if (output != null) {
                if (!TextUtils.isEmpty(output.getUserTotalAmount())) {
                    amountTv.setText(VerifyUtil.decimalFormat(output.getUserTotalAmount()));
                }
                countTv.setText(output.getUserTradeCount() + "");
                totalTv.setText("共"+output.getTradeCount()+"笔，"+VerifyUtil.decimalFormat(output.getTotalAmount())+"元，"+output.getUserNumber()+"位顾客");
            }
        }
    }
}
